using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Demo
{
    public partial class Form1 : Form
    {
        RfidApiLib.RfidApi Api = new RfidApiLib.RfidApi();
        public byte IsoReading = 0;
        public byte EpcReading = 0;
        public int TagCnt = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void AddToListBox(string strMsg)
        {
            lInfo.Items.Add(strMsg);
            lInfo.SelectedIndex = lInfo.Items.Count - 1;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cCommPort.SelectedIndex = 0;
            cBaudrate.SelectedIndex = 0;
            bRs232Con.Enabled = true;
            bRs232Discon.Enabled = false;
            bTcpCon.Enabled = true;
            bTcpDiscon.Enabled = false;
            bReset.Enabled = false;

            bRfSet.Enabled = false;
            bRfQuery.Enabled = false;

            bAntSet.Enabled = false;
            bAntQuery.Enabled = false;

            bIsoId.Enabled = false;
            bIsoRead.Enabled = false;
            bIsoWrite.Enabled = false;
            bIsoLock.Enabled = false;
            bIsoQueryLock.Enabled = false;

            bEpcId.Enabled = false;
            bEpcRead.Enabled = false;
            bEpcWrite.Enabled = false;
            bEpcInit.Enabled = false;

            cIsoTimes.SelectedIndex = 0;
            cEpcTimes.SelectedIndex = 0;

            cEpcMembank.SelectedIndex = 1;
            int nLoop = 0;
            for (nLoop = 0; nLoop < 256; nLoop++)
                cEpcWordptr.Items.Add(Convert.ToString(nLoop));
            cEpcWordptr.SelectedIndex = 2;
            for (nLoop = 1; nLoop < 14; nLoop++)
                cEpcWordcnt.Items.Add(Convert.ToString(nLoop));
            cEpcWordcnt.SelectedIndex = 5;
            cmbUserLockLevel.SelectedIndex = 0;
        }

        private void bRs232Con_Click(object sender, EventArgs e)
        {
            int status;
            byte v1 = 0;
            byte v2 = 0;
            string s = "";
            status = Api.OpenCommPort(cCommPort.SelectedItem.ToString());
            if (status != 0)
            {
                AddToListBox("Open Comm Port Failed!");
                return;
            }
            System.Threading.Thread.Sleep(100);
            status = Api.GetFirmwareVersion(ref v1,ref v2);
            if (status != 0)
            {
                AddToListBox("Can not connect with the reader!");
                Api.CloseCommPort();
                return;
            }

            AddToListBox("Connect the reader success!");
            s = string.Format("The reader's firmware version is:V{0:d2}.{1:d2}", v1, v2);
            AddToListBox(s);
            bTcpCon.Enabled = false;

            bReset.Enabled = true;

            bRs232Con.Enabled = false;
            bRs232Discon.Enabled = true;

            bRfSet.Enabled = true;
            bRfQuery.Enabled = true;

            bAntSet.Enabled = true;
            bAntQuery.Enabled = true;

            bIsoId.Enabled = true;
            bIsoRead.Enabled = true;
            bIsoWrite.Enabled = true;
            bIsoLock.Enabled = true;
            bIsoQueryLock.Enabled = true;

            bEpcId.Enabled = true;
            bEpcRead.Enabled = true;
            bEpcWrite.Enabled = true;
            bEpcInit.Enabled = true;

            //this.bRfQuery_Click(null,null);
            this.bAntQuery_Click(null, null);

        }

        private void bRs232Discon_Click(object sender, EventArgs e)
        {
            Api.CloseCommPort();
            bRs232Con.Enabled = true;
            bRs232Discon.Enabled = false;
            bTcpCon.Enabled = true;
            bTcpDiscon.Enabled = false;
            bReset.Enabled = false;

            bRfSet.Enabled = false;
            bRfQuery.Enabled = false;

            bAntSet.Enabled = false;
            bAntQuery.Enabled = false;

            bIsoId.Enabled = false;
            bIsoRead.Enabled = false;
            bIsoWrite.Enabled = false;
            bIsoLock.Enabled = false;
            bIsoQueryLock.Enabled = false;

            bEpcId.Enabled = false;
            bEpcRead.Enabled = false;
            bEpcWrite.Enabled = false;
            bEpcInit.Enabled = false;
        }

        private void bTcpCon_Click(object sender, EventArgs e)
        {
            int status;
            int port;
            byte v1 = 0;
            byte v2 = 0;
            string s = "";
            try
            {
                port = int.Parse(tPort.Text);
                s = tIp.Text;
                
            }
            catch (Exception)
            {
                AddToListBox("Please input the ip address and port !");
                return;
            }
            status = Api.TcpConnectReader(tIp.Text, port);
            if (status != 0)
            {
                AddToListBox("Connect Reader Failed!");
                return;
            }
            status = Api.GetFirmwareVersion(ref v1, ref v2);
            if (status != 0)
            {
                AddToListBox("Can not connect with the reader!");
                Api.TcpCloseConnect();
                return;
            }
            AddToListBox("Connect the reader success!");
            s = string.Format("The reader's firmware version is:V{0:d2}.{1:d2}", v1, v2);
            AddToListBox(s);
            bTcpCon.Enabled = false;
            bTcpDiscon.Enabled = true;

            bReset.Enabled = true;

            bRs232Con.Enabled = false;
            bRs232Discon.Enabled = false;

            bRfSet.Enabled = true;
            bRfQuery.Enabled = true;

            bAntSet.Enabled = true;
            bAntQuery.Enabled = true;

            bIsoId.Enabled = true;
            bIsoRead.Enabled = true;
            bIsoWrite.Enabled = true;
            bIsoLock.Enabled = true;
            bIsoQueryLock.Enabled = true;

            bEpcId.Enabled = true;
            bEpcRead.Enabled = true;
            bEpcWrite.Enabled = true;
            bEpcInit.Enabled = true;
            this.bRfQuery_Click(null, null);
            this.bAntQuery_Click(null, null);
        }

        private void bTcpDiscon_Click(object sender, EventArgs e)
        {
            Api.TcpCloseConnect();            
            bRs232Con.Enabled = true;
            bRs232Discon.Enabled = false;
            bTcpCon.Enabled = true;
            bTcpDiscon.Enabled = false;
            bReset.Enabled = false;

            bRfSet.Enabled = false;
            bRfQuery.Enabled = false;

            bAntSet.Enabled = false;
            bAntQuery.Enabled = false;

            bIsoId.Enabled = false;
            bIsoRead.Enabled = false;
            bIsoWrite.Enabled = false;
            bIsoLock.Enabled = false;
            bIsoQueryLock.Enabled = false;

            bEpcId.Enabled = false;
            bEpcRead.Enabled = false;
            bEpcWrite.Enabled = false;
            bEpcInit.Enabled = false;
        }

        private void bRfQuery_Click(object sender, EventArgs e)
        {
            byte pwr = 0;
            byte freq = 0;

            int status;
            string strSn="";
            Api.GetDeviceSN(ref strSn);
            status = Api.GetRf(ref pwr, ref freq);
            if (status != 0)
            {
                AddToListBox("Get Rf settings failed!");
                return;
            }
            tRfPwr.Value = pwr;
            cRfFreq.SelectedIndex = freq;
            AddToListBox("Get Rf settings success!");
        }

        private void bRfSet_Click(object sender, EventArgs e)
        {
            byte pwr = 0;
            byte freq = 0;

            int status;
            pwr = (byte)(tRfPwr.Value);
            freq = (byte)(cRfFreq.SelectedIndex);
            status = Api.SetRf(pwr, freq);
            if (status != 0)
            {
                AddToListBox("Set Rf settings failed!");
                return;
            }
            AddToListBox("Set Rf settings success!");
        }

        private void bAntQuery_Click(object sender, EventArgs e)
        {
            byte ant_sel = 0;

            int status;

            status = Api.GetAnt(ref ant_sel);
            if (status != 0)
            {
                AddToListBox("Get Ant settings failed!");
                return;
            }
            AddToListBox("Get Ant settings success!");
            if ((ant_sel & 0x01) == 0x01)
                ant1.Checked = true;
            else
                ant1.Checked = false;
            if ((ant_sel & 0x02) == 0x02)
                ant2.Checked = true;
            else
                ant2.Checked = false;
            if ((ant_sel & 0x04) == 0x04)
                ant3.Checked = true;
            else
                ant3.Checked = false;
            if ((ant_sel & 0x08) == 0x08)
                ant4.Checked = true;
            else
                ant4.Checked = false;
        }

        private void bAntSet_Click(object sender, EventArgs e)
        {
            byte ant_sel = 0;
            int status;

            if (ant1.Checked)
                ant_sel |= 0x01;
            if (ant2.Checked)
                ant_sel |= 0x02;
            if (ant3.Checked)
                ant_sel |= 0x04;
            if (ant4.Checked)
                ant_sel |= 0x08;

            status = Api.SetAnt(ant_sel);
            if (status != 0)
            {
                AddToListBox("Set ant failed!");
                return;
            }
            AddToListBox("Set ant success!");
        }

        private void bIsoId_Click(object sender, EventArgs e)
        {
            if (IsoReading == 0)
            {
                Api.ClearIdBuf();
                lInfo.Items.Clear();
                AddToListBox("Start multiply tags identify!");
                TagCnt = 0;
                timer1.Interval = (tIsoSpeed.Value + 1) * 20;
                timer1.Enabled = true;
                bIsoId.Text = "Stop";
                IsoReading = 1;
            }
            else
            {
                timer1.Enabled = false;
                IsoReading = 0;
                bIsoId.Text = "Identify";
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            DateTime dtStart = DateTime.Now;
            int status;
            int i,j;
            byte[,] IsoBuf = new byte[100,12];
            byte tag_cnt = 0;
            string s = "";
            string s1 = "";
            int listIn = 0;
            // Filter same tag
            if (!chkFilter.Checked)
                Api.ClearIdBuf();
            status = Api.IsoMultiTagIdentify(ref IsoBuf, ref tag_cnt);
            if (tag_cnt > 0)
            {
                for (i = 0; i < tag_cnt; i++)
                {
                    s1 = "";
                    for (j = 0; j < 8; j++)
                    {
                        s = string.Format("{0:X2} ", IsoBuf[i, j]);
                        s1 += s;
                    }
                    AddToListBox(s1);
                    ListViewItem lviList = new ListViewItem();
                    if (lvTagList.Items.Count <= 0)
                    {
                        lviList.SubItems[0].Text = "1";
                        for (i = 0; i <= 2; i++)
                            lviList.SubItems.Add("");
                        lvTagList.Items.Add(lviList);
                        listIn = 0;
                        lvTagList.Items[listIn].SubItems[1].Text = s1;
                        lvTagList.Items[listIn].SubItems[2].Text = "1";
                    }
                    else
                    {
                        listIn = -1;
                        for (i = 0; i < lvTagList.Items.Count; i++)
                        {
                            if (lvTagList.Items[i].SubItems[1].Text == s1)
                            {
                                listIn = i;
                                break;
                            }
                        }
                        if (listIn < 0)
                        {
                            listIn = lvTagList.Items.Count;
                            lviList.SubItems[0].Text = Convert.ToString(listIn + 1);
                            for (i = 0; i <= 2; i++)
                                lviList.SubItems.Add("");
                            lvTagList.Items.Add(lviList);
                        }
                        lvTagList.Items[listIn].SubItems[1].Text = s1;
                        if (lvTagList.Items[listIn].SubItems[2].Text == "")
                            lvTagList.Items[listIn].SubItems[2].Text = "0";
                        Int64 intTimes = Convert.ToInt64(lvTagList.Items[listIn].SubItems[2].Text);
                        lvTagList.Items[listIn].SubItems[2].Text = Convert.ToString(intTimes + 1);
                    }
                    TagCnt++;
                   
                }
            }
        }

        private void bEpcId_Click(object sender, EventArgs e)
        {
            if (EpcReading == 0)
            {
                Api.ClearIdBuf();
                Api.EpcIdentifyStart();
                lInfo.Items.Clear();
                AddToListBox("Start multiply tags identify!");
                TagCnt = 0;
                timer2.Interval = (tEpcSpeed.Value + 1) * 20;
                timer2.Enabled = true;
                bEpcId.Text = "Stop";
                EpcReading = 1;
            }
            else
            {
                Api.EpcIdentifyStop();
                timer2.Enabled = false;
                EpcReading = 0;
                bEpcId.Text = "Identify";
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            int status;
            int i, j;
            byte[,] IsoBuf = new byte[200, 14];
            byte tag_cnt = 0;
            string s = "";
            string s1 = "";
            byte tag_flag = 0;
            int listIn = 0;

            // Filter same tag
            if (!chkFilter.Checked)
                Api.ClearIdBuf();
            status = Api.EpcMultiTagIdentify(ref IsoBuf, ref tag_cnt, ref tag_flag);
            status = Api.ReciveTagData(ref IsoBuf, ref tag_cnt);
            if (tag_cnt > 0)
            {
                for (int iLoop = 0; iLoop < tag_cnt; iLoop++)
                {
                    s1 = "";
                    for (j = 0; j < Convert.ToInt16(cEpcWordcnt.Text) * 2; j++)
                    {
                        s = string.Format("{0:X2} ", IsoBuf[iLoop, j]);
                        s1 += s;
                    }
                    AddToListBox(s1);
                    ListViewItem lviList = new ListViewItem();
                    if (lvTagList.Items.Count <= 0)
                    {
                        lviList.SubItems[0].Text = "1" ;
                        for (i = 0; i <= 2; i++)
                            lviList.SubItems.Add("");
                        lvTagList.Items.Add(lviList);
                        listIn = 0;
                        lvTagList.Items[listIn].SubItems[1].Text = s1;
                        lvTagList.Items[listIn].SubItems[2].Text = "1";
                    }
                    else
                    {
                        listIn = -1;
                        for (i = 0; i < lvTagList.Items.Count; i++)
                        {
                            if (lvTagList.Items[i].SubItems[1].Text == s1)
                            {
                                listIn = i;
                                break;
                            }
                        }
                        if (listIn < 0)
                        {
                            listIn = lvTagList.Items.Count;
                            lviList.SubItems[0].Text = Convert.ToString( listIn + 1);
                            for (iLoop = 0; iLoop <= 2; iLoop++)
                                lviList.SubItems.Add("");
                            lvTagList.Items.Add(lviList);
                        }
                        lvTagList.Items[listIn].SubItems[1].Text = s1;
                        if (lvTagList.Items[listIn].SubItems[2].Text == "")
                            lvTagList.Items[listIn].SubItems[2].Text = "0";
                        Int64 intTimes = Convert.ToInt64(lvTagList.Items[listIn].SubItems[2].Text);
                        lvTagList.Items[listIn].SubItems[2].Text = Convert.ToString(intTimes + 1);
                    }
                }
            }
        }

        private void bIsoRead_Click(object sender, EventArgs e)
        {
            int addr;
            int len;
            int i = 0;
            int status = 0;
            byte[] value = new byte[32];
            string s = "The data is:";
            string s1 = "";
            try
            {
                addr = int.Parse(tIsoAddr.Text);
                len = int.Parse(tIsoCnt.Text);
            }
            catch (Exception)
            {
                AddToListBox("Please input ByteAddr and ByteCnt");
                return;
            }

            for (i = 0; i < len; )
            {
                status = Api.IsoRead((byte)addr, ref value);
                if (status != 0)
                {
                    AddToListBox("Read failed!");
                    return;
                }
                
                for (int j = 0; j < 8; j++)
                {
                    s1 = string.Format("{0:X2}", value[j]);
                    s += s1;
                    if (i + j >= len-1)
                        break;
                }
                i += 8;
            }
            if (status == 0)
            {
                AddToListBox("Read success!");
                AddToListBox(s);
            }
            
        }

        private void bIsoWrite_Click(object sender, EventArgs e)
        {
            byte[] value = new byte[16];
            int i = 0;
            int len;
            int addr;
            int status;
            string hexValues;
            try
            {
                addr = int.Parse(tIsoAddr.Text);
                len = int.Parse(tIsoCnt.Text);
                hexValues = tIsoData.Text;
            }
            catch (Exception)
            {
                AddToListBox("Please input the ByteAddr,ByteCnt and Data");
                return;
            }
            string[] hexValuesSplit = hexValues.Split(' ');
            try
            {
                foreach (String hex in hexValuesSplit)
                {
                    // Convert the number expressed in base-16 to an integer.
                    int x = Convert.ToInt32(hex, 16);
                    value[i++] = (byte)x;
                }
            }
            catch (Exception)
            {
                AddToListBox("Please input data needed");
                return;

            }
            if(i != len)
            {
                AddToListBox("Please input data needed");
                return;
            }
            for (i = 0; i < len; i++)
            {
                status = Api.IsoWrite((byte)(addr+i), value[i]);
                if (status != 0)
                {
                    AddToListBox("Write failed!");
                    return;
                }
            }
            AddToListBox("Write success!");
        }

        private void bEpcRead_Click(object sender, EventArgs e)
        {
            int membank;
            int wordptr;
            int wordcnt;
            int status = 0;
            byte[] value = new byte[16];

            string s = "The data is:";
            string s1 = "";

            membank = cEpcMembank.SelectedIndex;
            wordptr = cEpcWordptr.SelectedIndex;
            wordcnt = cEpcWordcnt.SelectedIndex + 1;

            status = Api.EpcRead((byte)membank, (byte)wordptr, (byte)wordcnt, ref value);

            if (status != 0)
            {
                AddToListBox("Read failed!");
                return;
            }
            else
            {
                for (int i = 0; i < wordcnt * 2; i++)
                {
                    s1 = string.Format("{0:X2}", value[i]);
                    s += s1;
                }
                AddToListBox("Read success!");
                AddToListBox(s);
            }
        }

        private void bClear_Click(object sender, EventArgs e)
        {
            lInfo.Items.Clear();
            lvTagList.Items.Clear();
        }

        private void bEpcInit_Click(object sender, EventArgs e)
        {
            int status;

            status = Api.EpcInitEpc(96);

            if (status == 0)
            {
                AddToListBox("Init tag success!");
            }
            else
            {
                AddToListBox("Init tag failed!");
            }
        }

        private void bEpcWrite_Click(object sender, EventArgs e)
        {
            ushort[] value = new ushort[16];
            int i = 0;
            byte membank;
            byte wordptr;
            byte wordcnt;
            int status = 0;
            string hexValues;

            membank = (byte)(cEpcMembank.SelectedIndex);
            wordptr = (byte)(cEpcWordptr.SelectedIndex);
            wordcnt = (byte)(cEpcWordcnt.SelectedIndex+1);

            hexValues = tEpcData.Text;
            string[] hexValuesSplit = hexValues.Split(' ');

            foreach (String hex in hexValuesSplit)
            {
                // Convert the number expressed in base-16 to an integer.
                if (hex != "")
                {
                    int x = Convert.ToInt32(hex, 16);
                    value[i++] = (ushort)x;
                }
            }

            if (i != wordcnt)
            {
                AddToListBox("Please input data needed");
                return;
            }
            for(byte j = 0; j < wordcnt; j++)
            {
                for (int nRetry = 0; nRetry < 3; nRetry++)
                {
                    status = Api.EpcWrite(membank, (byte)(wordptr + j), value[j]);
                    if (status == 0)
                        break;
                }
                if (status != 0)
                {
                    AddToListBox("Write failed!");
                    return;
                }
            }
            AddToListBox("Write success!");
        }

        private void tIsoData_TextChanged(object sender, EventArgs e)
        {
            if (((tIsoData.Text.Length-2) % 3) == 0)
            {
                tIsoData.Text += " ";
                tIsoData.Select(tIsoData.Text.Length,0);
            }
        }

        private void tEpcData_TextChanged(object sender, EventArgs e)
        {

        }

        private void bIsoLock_Click(object sender, EventArgs e)
        {
            int addr = 0;
            int status;

            try
            {
                addr = int.Parse(tIsoAddr.Text);
            }
            catch(Exception)
            {
                AddToListBox("Please Input ByteAddr!");
                return;
            }
            status = Api.IsoLock((byte)addr);
            if (status == 0)
            {
                AddToListBox("Lock success!");
            }
            else
            {
                AddToListBox("Lock failed!");
            }
        }

        private void btnISOReadWithID_Click(object sender, EventArgs e)
        {
            int addr;
            int len;
            int i = 0;
            int status = 0;
            byte byAntenna = 0;
            byte[] TagID = new byte[16];
            byte[] value = new byte[32];
            string s = "The data is:";
            string s1 = "";
            try
            {
                addr = int.Parse(tIsoAddr.Text);
                len = int.Parse(tIsoCnt.Text);
            }
            catch (Exception)
            {
                AddToListBox("Please input ByteAddr and ByteCnt");
                return;
            }
            string hexValues = txtTagID.Text;
            string[] hexValuesSplit = hexValues.Split(' ');
            try
            {
                foreach (String hex in hexValuesSplit)
                {
                    // Convert the number expressed in base-16 to an integer.
                    int x = Convert.ToInt32(hex, 16);
                    TagID[i++] = (byte)x;
                }
            }
            catch (Exception)
            {
                AddToListBox("Please input Tag ID needed");
                return;

            }
            if (i != 8)
            {
                AddToListBox("Please input Tag ID needed");
                return;
            }
            
            for (i = 0; i < len; )
            {
                status = Api.IsoReadWithID(TagID,(byte)addr, ref value,ref byAntenna);
                if (status != 0)
                {
                    AddToListBox("Read failed!");
                    return;
                }

                for (int j = 0; j < 8; j++)
                {
                    s1 = string.Format("{0:X2}", value[j]);
                    s += s1;
                    if (i + j >= len - 1)
                        break;
                }
                i += 8;
            }
            if (status == 0)
            {
                AddToListBox("Read success!");
                AddToListBox(s);
            }
        }

        private void btnISOWriteWithID_Click(object sender, EventArgs e)
        {
            int addr;
            int len;
            int i = 0;
            int status = 0;
            byte[] TagID = new byte[16];
            byte[] value = new byte[32];

            try
            {
                addr = int.Parse(tIsoAddr.Text);
                len = int.Parse(tIsoCnt.Text);
            }
            catch (Exception)
            {
                AddToListBox("Please input ByteAddr and ByteCnt");
                return;
            }
            string hexID = txtTagID.Text;
            string[] hexIDSplit = hexID.Split(' ');
            try
            {
                foreach (String hex in hexIDSplit)
                {
                    // Convert the number expressed in base-16 to an integer.
                    int x = Convert.ToInt32(hex, 16);
                    TagID[i++] = (byte)x;
                }
            }
            catch (Exception)
            {
                AddToListBox("Please input Tag ID needed");
                return;

            }
            string hexValues = tIsoData.Text;
            string[] hexValuesSplit = hexValues.Split(' ');
            try
            {
                i = 0;
                foreach (String hex in hexValuesSplit)
                {
                    // Convert the number expressed in base-16 to an integer.
                    if (hex != "")
                    {
                        int x = Convert.ToInt32(hex, 16);
                        value[i++] = (byte)x;
                    }
                }
            }
            catch (Exception)
            {
                AddToListBox("Please input data needed");
                return;

            }
            if (i != len)
            {
                AddToListBox("Please input data needed");
                return;
            }
            for (i = 0; i < len; i++)
            {
                status = Api.IsoWriteWithID(TagID,(byte)(addr + i), value[i]);
                if (status != 0)
                {
                    AddToListBox("Write failed!");
                    return;
                }
            }
            AddToListBox("Write success!");
        }

        private void btnList_Click(object sender, EventArgs e)
        {
            lvTagList.Visible = true;
            lInfo.Visible = false;
        }

        private void btnDetail_Click(object sender, EventArgs e)
        {
            lvTagList.Visible = false;
            lInfo.Visible = true;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            if (Api.Opened)
            {
                timer1.Enabled = false;
                timer2.Enabled = false;
                Api.CloseCommPort();
            }
            this.Close();
        }

        private void bReset_Click(object sender, EventArgs e)
        {
            //Api.ResetReader();
            bRs232Con.Enabled = true;
            bRs232Discon.Enabled = false;
            bTcpCon.Enabled = true;
            bTcpDiscon.Enabled = false;
            bReset.Enabled = false;

            bRfSet.Enabled = false;
            bRfQuery.Enabled = false;

            bAntSet.Enabled = false;
            bAntQuery.Enabled = false;

            bIsoId.Enabled = false;
            bIsoRead.Enabled = false;
            bIsoWrite.Enabled = false;
            bIsoLock.Enabled = false;
            bIsoQueryLock.Enabled = false;

            bEpcId.Enabled = false;
            bEpcRead.Enabled = false;
            bEpcWrite.Enabled = false;
            bEpcInit.Enabled = false;

        }

        private void btnSetIP_Click(object sender, EventArgs e)
        {
            //int status = 1;
            //status = Api.SetTcpParameter(txtNetIP.Text, txtSubNet.Text, txtDefaultGate.Text, Convert.ToInt16(txtTcpPort.Text));
            //if (status == 0)
            //    AddToListBox("Set TCP paramter success!");
            //else
            //    AddToListBox("Set TCP paramter failed!");
        }

        private void btnQueryIP_Click(object sender, EventArgs e)
        {
            //int status = 1;
            //string strIP = "", strMark = "", strGate = "";
            //int nPort = 0;
            //status = Api.GetTcpParameter(ref strIP, ref strMark, ref strGate, ref nPort);
            //if (status == 0)
            //{
            //    txtNetIP.Text = strIP;
            //    txtSubNet.Text = strMark;
            //    txtDefaultGate.Text = strGate;
            //    txtTcpPort.Text = Convert.ToString(nPort);
            //    AddToListBox("Get TCP paramter success!");
            //}
            //else
            //    AddToListBox("Get TCP paramter failed!");
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            //if (e.KeyValue == 13)
            //    cCommPort.DropDown;
        }
        // ÅúÁ¿Ð´Èë
        private void btnBatchWrite_Click(object sender, EventArgs e)
        {

        }

        private void btnEPCLock_Click(object sender, EventArgs e)
        {
            int status = Api.EpcLockTag((byte)cEpcMembank.SelectedIndex, (byte)cmbUserLockLevel.SelectedIndex);
            if (status != 0)
            {
                AddToListBox("Lock failed!");
                return;
            }
            AddToListBox("Lock success!");
        }

        private void bEpcKill_Click(object sender, EventArgs e)
        {

        }
    }
}